package com.tanhua.manage.listener;

import com.tanhua.dubbo.api.mongo.SoundApi;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

@Component
public class VipRedisLisenter extends KeyExpirationEventMessageListener {
    @Reference
    private SoundApi soundApi;

    public VipRedisLisenter(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.out.println("监听器进来了");
        String keyExpird = message.toString();
        if (keyExpird.contains("VIP_AD_")){
            String userId = keyExpird.replace("VIP_AD_", "");
            System.out.println("用户id为:"+userId);
            soundApi.updateSoundTimeAdOntime(userId,0);
        }
    }
}